package com.example.child_protection.controller;

import com.example.child_protection.dto.base.BaseResponseDTO;
import com.example.child_protection.dto.request.SimpleIdRequestDTO;
import com.example.child_protection.dto.request.add.AttrInsertRequestDTO;
import com.example.child_protection.dto.request.find.AttrRequestDTO;
import com.example.child_protection.dto.request.find.CheckCodeRequestDTO;
import com.example.child_protection.dto.request.update.AttrUpdateRequestDTO;
import com.example.child_protection.dto.response.AttrListResponseDTO;
import com.example.child_protection.dto.response.AttrResponseDTO;
import com.example.child_protection.dto.response.CheckCodeResponseDTO;
import com.example.child_protection.dto.response.SystemMenuButtonResponseDTO;
import com.example.child_protection.service.AttrManageService;
import com.example.child_protection.service.AttrQueryService;
import com.example.child_protection.util.ContentType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 属性管理控制层
 * @date 2018-11-2
 * @author Biz
 */
@RestController
@RequestMapping("attr")
@Api(value = "/api-attr", description = "属性管理")
public class AttrController extends BaseController {

    @Autowired
    public AttrManageService attrManageService;

    @Autowired
    public AttrQueryService attrQueryService;

    @ApiOperation(value ="查询属性", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findId", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public AttrResponseDTO findId(SimpleIdRequestDTO requestDTO,HttpServletRequest request)throws Exception{
        AttrResponseDTO responseDTO = attrQueryService.findId(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="查询属性列表信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findList", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public AttrListResponseDTO findList(AttrRequestDTO requestDTO, HttpServletRequest request)throws Exception{
        AttrListResponseDTO responseDTO = attrQueryService.findList(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="根据类目ID查询属性列表信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findListByCategoryId", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public AttrListResponseDTO findListByCategoryId(AttrRequestDTO requestDTO, HttpServletRequest request)throws Exception{
        AttrListResponseDTO responseDTO = attrQueryService.findListByCategoryId(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="检测属性CODE是否重复", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/checkCode", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public CheckCodeResponseDTO checkCode(CheckCodeRequestDTO requestDTO, HttpServletRequest request)throws Exception{
        CheckCodeResponseDTO responseDTO = attrQueryService.checkCode(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="添加属性", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/insert", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO insert(AttrInsertRequestDTO requestDTO)throws Exception{
        requestDTO.setCreatePersonId(this.getLoginUserId());
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = attrManageService.insert(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="修改属性", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO update(AttrUpdateRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = attrManageService.update(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="删除属性", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO delete(SimpleIdRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = attrManageService.delete(requestDTO);
        return responseDTO;
    }

}
